﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Imaginecup.sprite;
using imaginecup.util;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.util.resourceMan;
using Imaginecup.sprite.changeSourceSize;
using Imaginecup.gameState.water.controller.phone;
using Imaginecup.util.touchMan;
using Imaginecup.util.input;
using Imaginecup.gameState.water.mapMan;

namespace Imaginecup.gameState.water.controller
{
    public class PhoneController : IController , ITouchProcessRegister
    {
        LeftController leftController;
        RightController rightController;

        private TouchMan m_TouchMan;

        public PhoneController()
        {
            leftController = new LeftController();
            rightController = new RightController();

            m_TouchMan = new TouchMan();

        }

        public void SetMapManager(MapMan mapManager)
        {
            leftController.SetMapManager(mapManager);
        }

        public void Update(GameTime gameTime)
        {
            leftController.Update(gameTime);
            rightController.Update(gameTime);

            IPhoneInputHandler phoneInput = PhoneInputHandler.GetInputHandler();

            TouchUtil.Update(phoneInput.GetCurrentTouch(), m_TouchMan, this);
        }
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            leftController.Draw(gameTime, spriteBatch);
            rightController.Draw(gameTime, spriteBatch);
        }

        public void RegisterTouch(Microsoft.Xna.Framework.Input.Touch.TouchLocation touch)
        {
            if( leftController.CheckLocation(touch) )
            {
                m_TouchMan.AddTouchProcess(touch, leftController);
            }
            else if( rightController.CheckLocation(touch) )
            {
                m_TouchMan.AddTouchProcess(touch, rightController);
            }
        }
    }
}
